package com.medvalley.tcm.controller;

import com.google.common.collect.Maps;
import com.medvalley.tcm.base.Result;
import com.medvalley.tcm.service.impl.SleepDataService;
import com.medvalley.tcm.vo.inputvo.SleepDataInputVo;
import com.medvalley.tcm.vo.outputvo.SleepDataOutputVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

@Api("睡眠接口")
@RestController
@RequestMapping("/sleep")
public class SleepController extends BaseController {

    @Autowired
    private SleepDataService sleepDataService;


    @PostMapping("/upload_data")
    @ApiOperation("上传睡眠数据")
    public Result uploadSleepData(@RequestParam SleepDataInputVo sleepDataInputVo, HttpServletRequest request) {
        long userId = getUserId(request);
        sleepDataService.saveSleepData(userId, sleepDataInputVo);
        return success();
    }

    @GetMapping("/list/dates")
    @ApiOperation("睡眠日期列表,列出有睡眠记录的日期列表")
    public Result listSleepRecord(HttpServletRequest request) {
        long userId = getUserId(request);
        List<String> records = sleepDataService.listSleepRecordDate(userId);
        return success(records);
    }

    @GetMapping("/list/record_detail")
    @ApiOperation("睡眠数据详情")
    public Result sleepDataDetail(@RequestParam String recordDate, HttpServletRequest request) {
        long userId = getUserId(request);
        SleepDataOutputVo sleepDataOutputVo = sleepDataService.sleepDateDetail(userId, recordDate);
        return success(sleepDataOutputVo);
    }

    @GetMapping("/recent_seven_data")
    @ApiOperation("最近七次数据")
    public Result historyData(HttpServletRequest request) {
        //TODO
        return success();
    }

    @GetMapping("/list/standard_value")
    @ApiOperation("睡眠质量参考值")
    public Result standardValue() {
        Map<String, String> standardValue = Maps.newHashMap();
        standardValue.put("sleepDuration", "7-8小时");
        standardValue.put("preSleepDuration", "<15分钟"); // 入睡时长
        standardValue.put("lightSleep", "<55%");
        standardValue.put("deepSleep", ">20%");
        standardValue.put("turnOverTime", "25次");
        return success(standardValue);
    }

    @GetMapping("/suggest")
    @ApiOperation("睡眠建议")
    public Result suggest() {
        return success();
    }

}
